package com.ssyc.gsk_parents.adapter;


import android.content.Context;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.ssyc.common.glide.ImageUtil;
import com.ssyc.common.manager.PickChooseManager;
import com.ssyc.common.utils.ScreenUtils;
import com.ssyc.common.utils.UiUtils;
import com.ssyc.gsk_parents.R;

import java.util.List;

/**
 * 用于RecyclerView显示图片的适配器
 * Created by Administrator on 2018/5/9 0009.
 */

public class RvShowPicAdapter extends BaseQuickAdapter<String, BaseViewHolder> {
    private Context context;
    private List<String> mUrls;
    private LinearLayout.LayoutParams lp;

    public RvShowPicAdapter(Context context, int layoutResId, @Nullable List<String> data) {
        super(layoutResId, data);
        this.context = context;
        this.mUrls = data;
        //配置图片的布局参数
        initParams(context);
    }

    /**
     * 配置图片的布局参数
     *
     * @param context
     */
    private void initParams(Context context) {
        //计算图片的大小
        int screenWidth = ScreenUtils.getScreenWidth(context);
        int ivWidth = (screenWidth - UiUtils.dp2px(16 * 2 + 8 * 2 + 6  + 6 * 3)) / 3;
        int ivHeight = ivWidth * 3 / 2;
        lp = new LinearLayout.LayoutParams(ivWidth, ivHeight);
    }

    @Override
    protected void convert(BaseViewHolder helper, String item) {
        //需要显示的图片
        ImageView img = helper.getView(R.id.iv);
        img.setLayoutParams(lp);
        ImageUtil.displayImage(context, img, mUrls.get(helper.getLayoutPosition()));
        img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //点击跳转到大图
                PickChooseManager.startShowBigActivity(context, mUrls, helper.getLayoutPosition());
            }
        });
    }
}
